package com.damocode.starter.httpclient.helper;

import java.util.Arrays;

public enum FormatType {
    XML(new String[]{"application/xml", "text/xml"}),
    JSON(new String[]{"application/json", "text/json"}),
    RAW(new String[]{"application/octet-stream"}),
    FORM(new String[]{"application/x-www-form-urlencoded"});

    private String[] formats;

    FormatType(String... formats) {
        this.formats = formats;
    }

    public static String mapFormatToAccept(FormatType format) {
        return format.formats[0];
    }

    public static FormatType mapAcceptToFormat(String accept) {
        FormatType[] formatTypes = values();
        for(int i = 0; i < formatTypes.length; ++i) {
            FormatType value = formatTypes[i];
            if (Arrays.asList(value.formats).contains(accept)) {
                return value;
            }
        }
        return RAW;
    }
}
